package com.ssm.gbq.controller;

import com.ssm.gbq.model.Complaint;
import com.ssm.gbq.service.ComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/complaint")
public class ComplaintController {
    @Autowired
    private ComplaintService complaintService;

    /**
     * 获取全部投诉信息
     * @Title: getAllComplaint
     * @param @return
     */
    @ResponseBody
    @RequestMapping(value = "/getALLComplaintTable", method = RequestMethod.POST)
    public HashMap<String, Object> getALLComplaintTable(Complaint complaint,Integer currentPage,Integer pageSize) throws Exception{
        HashMap<String,Object> result = new HashMap<String,Object>();
        Integer offSet = pageSize*(currentPage-1);
        List<Complaint> complaintList = complaintService.getALLComplaintTable(complaint,offSet,pageSize);
        result.put("data",complaintList);
        result.put("count",complaintService.getALLComplaintTableCount(complaint));
        return result;
    }
    /**
     * 添加
     */
    @ResponseBody
    @RequestMapping("/addComplaint")
    public String addComplaint(Complaint complaint){
        complaint.setCreate_time(new Date());
        int i = complaintService.addComplaint(complaint);
        if(i>0){
            return "添加成功";
        }else{
            return "添加失败";
        }
    }
    /**
     * 修改回显
     */
    @ResponseBody
    @RequestMapping("/toupdateComplaint")
    public Complaint toupdateComplaint(Integer id){
        Complaint complaint = complaintService.showComplaintById(id);
        return complaint;
    }
    /**
     * 修改保存
     */
    @ResponseBody
    @RequestMapping("/updateComplaint")
    public String updateComplaint(Complaint complaint){
        int i = complaintService.updateComplaint(complaint);
        if(i>0){
            return "修改成功";
        }else{
            return "修改失败";
        }
    }
    /**
     * 删除
     */
    @ResponseBody
    @RequestMapping("/delComplaint")
    public String delComplaint(Integer id){
        int i = complaintService.delComplaint(id);
        if(i>0){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }
}
